<?php
class Admin_Model_CurrentPage extends Zend_Db_Table{
	protected $_name = 'current_page';
	protected $_primary = 'page_id';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	////////////
	/* select*/
	//////////
	public function selectPageByCode($code)
	{// co dung
	
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/currentpage/route/selectPageByCode/code/".$code);
		
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
				
		return $data;
	}
	
	public function selectAllPage()
	{// co dung
		
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/currentpage/route/selectAllPage");
	
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
				
		return $data;
	}
	
	////////////
	/* insert*/
	//////////
	public function insertCurrentPage($data)
	{// co dung
		$data['route'] = "insertCurrentPage";
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPost("/currentpage", $data);

		return $return->getBody();
		
	}
	
	////////////
	/* update*/
	//////////
	public function updateCurrentPage($timenow,$page)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/currentpage/route/updateCurrentPage/timerow/".urlencode($timenow)."/page/".urlencode($page));
		return $return->getBody();
		
	}
	
	public function updatePropertiesCurrentPage($page,$data)
	{// co dung
		
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/currentpage/route/updatePropertiesCurrentPage/page/".urlencode($page)."/data/".urlencode($data));
		return $return->getBody();
	
	}
	
	////////////
	/* delete*/
	//////////
	public function deleteCurrentPage($page)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/currentpage/route/deleteCurrentPage/page/".$page);
		return $return->getBody();
		
	}
}